package com.example.park_management.controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

@RestController
public class PhotoRec_zyz{
    @PostMapping( "/updateUserAbility")
    public String updateUserAbility(String data) {
        InputStream result = null;
        String str = null;
        System.out.println(data);
        if (data == null) {
            return "输入的内容为空";
        }
        StringBuilder responseData = null;
        try (InputStream inputStream = new URL("http://127.0.0.1:5000/recommend/" + data).openStream()) {
            // 创建一个字节数组来存储读取到的数据
            byte[] buffer = new byte[1024];
            int bytesRead;
            responseData = new StringBuilder();

            while ((bytesRead = inputStream.read(buffer)) != -1) {
                // 从InputStream读取数据并将其存储在字节数组中
                String chunk = new String(buffer, 0, bytesRead);
                responseData.append(chunk);
            }

            // responseData 现在包含从URL读取的数据
            System.out.println("Received data: " + responseData.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }

        return responseData.toString();
    }
}
